package com.swgk.core.view.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.swgk.core.BR;
import com.swgk.core.R;
import com.swgk.core.base.aroute.ARouterStartWebBase;
import com.swgk.core.databinding.ItemEnterpriseRecMenuBinding;
import com.swgk.core.view.entity.EnterpriseRecEntity;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.recyclerview.adapter.PageRecycleAdapter;
import com.swgk.core.util.DisplayUtil;

import java.util.List;

public class EnterpriseRecMenuAdapter extends PageRecycleAdapter<EnterpriseRecEntity> {
    int size = 6;
    public EnterpriseRecMenuAdapter(Context context, List<EnterpriseRecEntity> data) {
        super(context, R.layout.item_enterprise_rec_menu, data);
        int winWith = DisplayUtil.getScreenWidth(context);
        if (winWith <= 900){
            size = 5;
        }else{
            size = 6;
        }
    }

    @Override
    public void convert(ItemViewHolder holder, EnterpriseRecEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ItemEnterpriseRecMenuBinding binding = (ItemEnterpriseRecMenuBinding) holder.getmBinding();
        if (!TextUtils.isEmpty(entity.getCompanyName())) {
            if (entity.getCompanyName().length() <= size) {
                binding.tvContent.setText(entity.getCompanyName() + ">");
            } else {
                binding.tvContent.setText(entity.getCompanyName().substring(0, size) + "...>");
            }
        }
        binding.getRoot().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ARouterStartWebBase.startWebSiteInfo(entity.getCompanyNo(), 1);
            }
        });
    }
}
